package com.three.lab.util;

import android.os.CountDownTimer;

/**
 * 通用计时器
 * create by lqd on 2024-06-05.
 */
public class MyCountDownTimer extends CountDownTimer {

    private OnCallBack callBack;

    public void setCallBack(OnCallBack callBack) {
        this.callBack = callBack;
    }

    public MyCountDownTimer(long millisInFuture, long countDownInterval, OnCallBack callBack) {
        super(millisInFuture, countDownInterval);
        this.callBack = callBack;
    }

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public MyCountDownTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        callBack.onTicking(millisUntilFinished);
    }

    @Override
    public void onFinish() {
        callBack.onFinish();
    }

    public interface OnCallBack{
        void onTicking(long millisUntilFinished);
        void onFinish();
    }
}
